package com.example.controller;

import com.example.demo.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Copyright © 2016年 author. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * @Date 2017/9/2 0002 20:52
 */
@RestController
public class demo {

    @Autowired
    MyService myService;
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    MyBean myBean;

    @Resource(name="stringRedisTemplate")
    ValueOperations<String,String> valOpsStr;


    @GetMapping("/home")
    String home() {
        System.out.println("=======home======="+myService.getMsg());
        myService.getMsg();
        return myService.sayHello();
    }

    @GetMapping("/redis")
    String redis() {

        valOpsStr.set("k5","v5");

        return "set ok!";

    }

    @PostMapping("/rest")
    public Map<String, Object> rest() {

        Map<String, Object> data = new HashMap<String, Object>();

        data.put("1", "A");
        data.put("2", 2);

        return data;

    }


    @PutMapping("/restput")
    public Map<String, Object> restput() {

        Map<String, Object> data = new HashMap<String, Object>();

        data.put("1", "A");
        data.put("2", "B");
        data.put("3","C");

        return data;

    }



}
